In [1]:
from sympy import *
init_printing()
t,x0,x1,x2,C=symbols('t,x0,x1,x2,C',real=true)

In [2]:
# defino la función F
def F(x):
    F=(x[1],-x[0]*C)
    return F

F((x1,x2))


Out[2]:
$$\left ( x_{2}, \quad - C x_{1}\right )$$

Ejercicio resorte


In [3]:
#calculo la phi_n por el método de Picard
x0=(0,1)
a=(0,C)
for j in range(10):
    a=((x0[0]+integrate(F(a)[0],t),x0[1]+integrate(F(a)[1],t)))

a


Out[3]:
$$\left ( \frac{C^{4} t^{9}}{362880} - \frac{C^{3} t^{7}}{5040} + \frac{C^{2} t^{5}}{120} - \frac{C t^{3}}{6} + t, \quad - \frac{C^{6} t^{10}}{3628800} + \frac{C^{4} t^{8}}{40320} - \frac{C^{3} t^{6}}{720} + \frac{C^{2} t^{4}}{24} - \frac{C t^{2}}{2} + 1\right )$$

In [4]:
#calculo el polinomio de Taylor de la solución
serietaylor=0
f=1/sqrt(C)*sin(sqrt(C)*t)
b=f.subs(t,0)
j=0
for j in range(10):
    serietaylor=serietaylor+b/(factorial(j))*t**j
    f=f.diff(t)
    b=f.subs(t,0)
    j=j+1
serietaylor


Out[4]:
$$\frac{C^{4} t^{9}}{362880} - \frac{C^{3} t^{7}}{5040} + \frac{C^{2} t^{5}}{120} - \frac{C t^{3}}{6} + t$$

Ejercicio $X'=AX$


In [5]:
#defino G
def G(x):
    G=(x[1],-x[0]-2*x[1])
    return G

G((x1,x2))


Out[5]:
$$\left ( x_{2}, \quad - x_{1} - 2 x_{2}\right )$$

In [6]:
x0=(0,1)
a=x0
for j in range(10):
    a=((x0[0]+integrate(G(a)[0],t),x0[1]+integrate(G(a)[1],t)))

a[1].simplify()


Out[6]:
$$\frac{11 t^{10}}{3628800} - \frac{t^{9}}{36288} + \frac{t^{8}}{4480} - \frac{t^{7}}{630} + \frac{7 t^{6}}{720} - \frac{t^{5}}{20} + \frac{5 t^{4}}{24} - \frac{2 t^{3}}{3} + \frac{3 t^{2}}{2} - 2 t + 1$$

Pasar de sistema de ecuaciones a ecuación sola


In [7]:
X=Function('X',positive=true)(t)
Y=Function('Y',positive=true)(t)
Z=Function('Z',positive=true)(t)

In [8]:
ec1=Eq(X.diff(t),X+Z)
ec2=Eq(Y.diff(t),t*X-Z)
ec3=Eq(Z.diff(t),-t**2*X+Y)
ec1, ec2, ec3


Out[8]:
$$\left ( \frac{d}{d t} X{\left (t \right )} = X{\left (t \right )} + Z{\left (t \right )}, \quad \frac{d}{d t} Y{\left (t \right )} = t X{\left (t \right )} - Z{\left (t \right )}, \quad \frac{d}{d t} Z{\left (t \right )} = - t^{2} X{\left (t \right )} + Y{\left (t \right )}\right )$$

In [9]:
ec4=Eq(ec1.lhs.diff(t),ec1.rhs.diff(t).subs(Y.diff(t),ec2.rhs).subs(Z.diff(t),ec3.rhs))
ec5=Eq(ec4.lhs.diff(t),ec4.rhs.diff(t).subs(Y.diff(t),ec2.rhs).subs(Z.diff(t),ec3.rhs))
ec1, ec4, ec5


Out[9]:
$$\left ( \frac{d}{d t} X{\left (t \right )} = X{\left (t \right )} + Z{\left (t \right )}, \quad \frac{d^{2}}{d t^{2}} X{\left (t \right )} = - t^{2} X{\left (t \right )} + Y{\left (t \right )} + \frac{d}{d t} X{\left (t \right )}, \quad \frac{d^{3}}{d t^{3}} X{\left (t \right )} = - t^{2} \frac{d}{d t} X{\left (t \right )} - t X{\left (t \right )} - Z{\left (t \right )} + \frac{d^{2}}{d t^{2}} X{\left (t \right )}\right )$$

In [10]:
solve([ec1,ec4,ec5], [X,Y,Z])


Out[10]:
$$\left \{ X{\left (t \right )} : \frac{1}{t - 1} \left(- t^{2} \frac{d}{d t} X{\left (t \right )} - \frac{d}{d t} X{\left (t \right )} + \frac{d^{2}}{d t^{2}} X{\left (t \right )} - \frac{d^{3}}{d t^{3}} X{\left (t \right )}\right), \quad Y{\left (t \right )} : \frac{1}{t - 1} \left(t^{2} \left(- t^{2} \frac{d}{d t} X{\left (t \right )} + \frac{d^{2}}{d t^{2}} X{\left (t \right )} - \frac{d^{3}}{d t^{3}} X{\left (t \right )}\right) - t^{2} \frac{d}{d t} X{\left (t \right )} + \left(t - 1\right) \left(- \frac{d}{d t} X{\left (t \right )} + \frac{d^{2}}{d t^{2}} X{\left (t \right )}\right)\right), \quad Z{\left (t \right )} : \frac{1}{t - 1} \left(t^{2} \frac{d}{d t} X{\left (t \right )} + t \frac{d}{d t} X{\left (t \right )} - \frac{d^{2}}{d t^{2}} X{\left (t \right )} + \frac{d^{3}}{d t^{3}} X{\left (t \right )}\right)\right \}$$

In [11]:
a,x,y=symbols('a,x,y')
solve([Eq(x**2+y,a), Eq(x+2*y,2*a)],[x,y])


Out[11]:
$$\left [ \left ( 0, \quad a\right ), \quad \left ( \frac{1}{2}, \quad a - \frac{1}{4}\right )\right ]$$

Ejercicio de iteracion de Picard, $\varphi'(x)=\varphi(x)^2$


In [110]:
f=Function('f')(x)
f=1+0*x
p=1
n=4

for i in range(n):
    f=f.subs(x,t)
    f=1+integrate(f**2,(t,0,x))
    p=p+x**(i+1)
f.expand()


Out[110]:
$$\frac{x^{15}}{59535} + \frac{x^{14}}{3969} + \frac{x^{13}}{567} + \frac{x^{12}}{126} + \frac{5 x^{11}}{189} + \frac{22 x^{10}}{315} + \frac{86 x^{9}}{567} + \frac{71 x^{8}}{252} + \frac{29 x^{7}}{63} + \frac{2 x^{6}}{3} + \frac{13 x^{5}}{15} + x^{4} + x^{3} + x^{2} + x + 1$$

In [ ]:


In [ ]: